package background;

/**
 * @ClassName MultiThreadsError
 * @Description TODO 第一种：运行结果出错。
 *                TODO 演示计数不准确（减少），找出具体出错的位置
 * @Author wushaopei
 * @Date 2021/4/24 18:23
 * @Version 1.0
 */
public class MultiThreadsError implements Runnable {

    static  MultiThreadsError instance = new MultiThreadsError();
    int index = 0;

    public static void main(String[] args) throws InterruptedException {
        Thread thread1 = new Thread(instance);
        Thread thread2 = new Thread(instance);
        thread1.start();
        thread2.start();
        thread1.join();
        thread2.join();
        System.out.println(instance.index);
    }

    @Override
    public void run() {
        for(int i = 0; i < 10000; i++){
            index++;
        }
    }
}
